package top.yjp.jtf.plugin.deprecated;

import com.intellij.openapi.project.Project;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.table.JBTable;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.util.List;
import java.util.Map;

public class ExcelEditorToolWindow {
    private final JPanel panel;
    private final JBTable table;

    public ExcelEditorToolWindow(Project project, List<Map<Integer, String>> data) {
        // 创建表格模型
        // 获取列数
        int columnCount = data.get(0).size();

        // 创建列名
        String[] columnNames = new String[columnCount];
        for (int i = 0; i < columnCount; i++) {
            columnNames[i] = data.get(0).get(i);//"Column " + (i + 1); // 使用适当的列名
        }
        DefaultTableModel model = new DefaultTableModel(columnNames, 0);

        for (Map<Integer, String> row : data) {
            Object[] rowData = new Object[columnNames.length];
            for (Map.Entry<Integer, String> entry : row.entrySet()) {
                rowData[entry.getKey()] = entry.getValue();
            }
            model.addRow(rowData);
        }

        table = new JBTable(model);
        JBScrollPane scrollPane = new JBScrollPane(table);

        panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
        panel.add(scrollPane);
    }

    public JPanel getPanel() {
        return panel;
    }

    public JBTable getTable() {
        return table;
    }
}
